﻿
using System.Windows.Data;
using System.Collections.ObjectModel;
using System;
using System.Collections.Generic;
using System.Data.Linq.Mapping;
using System.ComponentModel;
using System.Data.Linq;

namespace QuickWeb
{

    /// <summary>
    /// Esta clase representa lo que un feed ofrece de un aticulo
    /// </summary>
    public class FeedItem 
    {
        


        public string Title { get; set; }
        //public string Author { get; set; }
        public string Summary { get; set; }
        public DateTime PubDate { get; set; }
        public Uri Link { get; set; }
    }

    public class FeedItems : ObservableCollection<FeedItem>
    {

    }

    public class FeedData 
    {
        public string Title { get; set; }
        public string Description { get; set; }

        private FeedItems _Items = new FeedItems();
        public FeedItems Items
        {
            get
            {
                return this._Items;
            }
        }
    }

    public class FeedSources : ObservableCollection<FeedData>
    {

    }

    public class FeedArticleData
    {
        public string Title { get; set; }
        public string PreviewDescription { get; set; }
        public string ImagePath { get; set; }
        public string PublicationDateAndAuthor { get; set; }
        
        public Uri uri { get; set; }    
    }

    public class FeedArticleDataList : ObservableCollection<FeedArticleData>
    {

    }







    /// <summary>
    /// Esta clase representa una fuente de feeds
    /// </summary>
    [Table]
    public class FeedStored : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private string _Title;
        [Column]
        public string Title {
            get {
                return _Title;
            }
            set {
                if (_Title!=value)
                {
                    NotifyPropertyChanging("Title");
                    _Title = value;
                    NotifyPropertyChanged("Title");
                }
            }
        }
        
        private string _Description;
        [Column]
        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                if (_Description != value)
                {
                    NotifyPropertyChanging("Description");
                    _Description = value;
                    NotifyPropertyChanged("Description");
                }
            }
        }

        private string _Source;
        [Column]
        public string Source
        {
            get
            {
                return _Source;
            }
            set
            {
                if (_Source != value)
                {
                    NotifyPropertyChanging("Source");
                    _Source = value;
                    NotifyPropertyChanged("Source");
                }
            }
        }

        private string _Link;
        [Column]
        public string Link
        {
            get
            {
                return _Link;
            }
            set
            {
                if (_Link != value)
                {
                    NotifyPropertyChanging("Link");
                    _Link = value;
                    NotifyPropertyChanged("Link");
                }
            }
        }




        
        private int _ID;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int FeedSourceID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    NotifyPropertyChanging("FeedSourceID");
                    _ID = value;
                    NotifyPropertyChanged("FeedSourceID");
                }
            }
        }


        [Column(IsVersion = true)]
        private Binary _version;



        private bool _isComplete;
        [Column]
        public bool IsComplete
        {
            get { return _isComplete; }
            set
            {
                if (_isComplete != value)
                {
                    NotifyPropertyChanging("IsComplete");
                    _isComplete = value;
                    NotifyPropertyChanged("IsComplete");
                }
            }
        }




        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion


        #region INotifyPropertyChanging Members
        public event PropertyChangingEventHandler PropertyChanging;
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }
        #endregion
    }
    
    public class FeedsStoredContext : DataContext
    {
        public static string DBConnectionString = "Data Source=isostore:/FeedsStored.sdf";
        public FeedsStoredContext(string connectionString)
            : base(connectionString)
        { }
        public Table<FeedStored> items;
    }











    [Table]
    public class ClipStored : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private string _Title;
        [Column]
        public string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                if (_Title != value)
                {
                    NotifyPropertyChanging("Title");
                    _Title = value;
                    NotifyPropertyChanged("Title");
                }
            }
        }

        private string _Description;
        [Column]
        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                if (_Description != value)
                {
                    NotifyPropertyChanging("Description");
                    _Description = value;
                    NotifyPropertyChanged("Description");
                }
            }
        }
        
        private string _Link;
        [Column]
        public string Link
        {
            get
            {
                return _Link;
            }
            set
            {
                if (_Link != value)
                {
                    NotifyPropertyChanging("Link");
                    _Link = value;
                    NotifyPropertyChanged("Link");
                }
            }
        }


        private int _ID;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int FeedSourceID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    NotifyPropertyChanging("FeedSourceID");
                    _ID = value;
                    NotifyPropertyChanged("FeedSourceID");
                }
            }
        }


        [Column(IsVersion = true)]
        private Binary _version;



        private bool _isComplete;
        [Column]
        public bool IsComplete
        {
            get { return _isComplete; }
            set
            {
                if (_isComplete != value)
                {
                    NotifyPropertyChanging("IsComplete");
                    _isComplete = value;
                    NotifyPropertyChanged("IsComplete");
                }
            }
        }




        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion


        #region INotifyPropertyChanging Members
        public event PropertyChangingEventHandler PropertyChanging;
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }
        #endregion
    }





    public class ClipsStoredContext : DataContext
    {
        public static string DBConnectionString = "Data Source=isostore:/ClipsStored.sdf";
        public ClipsStoredContext(string connectionString)
            : base(connectionString)
        { }
        public Table<ClipStored> items;
    }




}